﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Progetto.Beans;
using Progetto.Model_Stuff;

namespace Progetto.Controller_Stuff
{
    class Controller
    {
        private Model_Stuff.Model _model;
        private User _user;
        private Authentication _auth = new Authentication();

        public Controller(Model_Stuff.Model model)
        {
            _model = model;
        }

        public bool LogIn(string email, string password)
        {
            throw new NotImplementedException();
            //utilizzerà _auth.LogIn()
        }

        public bool LogOut()
        {
            throw new NotImplementedException();
            //idem
        }


        public void AddCalendar(MyCalendar calendar)
        {
            _model.AddCalendar(_user, calendar);
        }

        public void AddFilter(IFilterDescriptor filter)
        {
            _model.AddFilter(_user, filter);
        }

        public void AddPublicEvent(Event e)
        {
            _model.AddPublicEvent(e);
        }

        public void AddEvent(List<MyCalendar> calendars, Event e)
        {
            _model.AddEvent(_user, calendars, e);
        }

        public bool IsAuthenticated(string email, string passwd)
        {
            throw new NotImplementedException();
        }

        public List<Event> getPublicEvents()
        {
            List<Event> publicEvents = new List<Event>();
            foreach (Event e in _model.GeneralCalendar.Events.Values)
                publicEvents.Add(e);
            return publicEvents;
        }

        public List<Event> getMyEvents()
        {
            List<Event> myEvents = new List<Event>();
            foreach (MyCalendar calendar in _model.UserCalendarsList[_user])
            {
                foreach (Event e in calendar.GetPrivateEvents().Values)
                    myEvents.Add(e);

            }
            return myEvents;
        }

        public List<Event> getEventsFromCalendar(MyCalendar calendar)
        {
            List<Event> calendarEvents = new List<Event>();
            foreach (MyCalendar cal in _model.UserCalendarsList[_user])
            {
                if (cal.Name == calendar.Name)
                {
                    foreach (Event e in cal.Events.Values)
                        calendarEvents.Add(e);
                }
            }
            return calendarEvents;
        }

        public List<MyCalendar> getMyCalendars()
        {
            return _model.UserCalendarsList[_user];
        }

    }
}
